#region Header File
//
// Node.cs - Concurrent Code Block
//
// Copyright (C) Javier Valcarce. BSD License
#endregion

#region Using Statements
using System.Collections.Generic;
using System.Threading;
#endregion

namespace Arq
{
    /// <summary>
    /// Concurrent node with a Dispatcher
    /// </summary>
    public abstract class Node 
    {

        // dispatcher of this concurrent node
        protected Dispatcher Dispatcher      { get; private set; }

        // thread in which run the Dispatcher
        private Thread th;
       
        /// <summary>
        /// Base constructor: adds the node to Graph. NodeList
        /// </summary>
        public Node(string name)
        {
            this.Dispatcher = new Dispatcher();
            th              = new Thread(MainThread);
            th.Name         = name;
            th.IsBackground = true;
           
        }
        
        protected void StartDispatherThread()
        {
             th.Start();
        }

        /// <summary>
        /// Thread with a Dispatcher
        /// </summary>
        private void MainThread()
        {
            Dispatcher.Run();
        }
      
    }

}
